package com.github.cosycode.flow.base;

import lombok.Data;

import java.util.LinkedList;

/**
 * <b>Description : </b>
 * <p>
 * <b>created in </b> 2022/12/15
 * </p>
 *
 * @author pengfchen
 * @since 1.0
 **/
@Data
public abstract class JobFlowContext {

    private String message;

    private boolean dryRun;

    private Exception exception;

    private LinkedList<JobStageRecord<?>> stageHistory;

    public void exec(IEnumStage<?> execStage) {
        while (execStage != null) {
            execStage = execStage.process(this);
        }
    }

    public void addJobStageRecord(JobStageRecord<?> jobStageRecord) {
        if (stageHistory == null) {
            stageHistory = new LinkedList<>();
        }
        stageHistory.add(jobStageRecord);
    }

}
